package com.aio.news.view;

import com.aio.news.utils.AppConstance;
import com.aio.news.utils.DisplayUtil;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

public class DetailMenuView extends LinearLayout {

	private int currentState = 0;// 0=top,1=bottom
	private static int duration = 300;

	public DetailMenuView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}

	public DetailMenuView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public DetailMenuView(Context context) {
		super(context);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		setMeasuredDimension(
				MeasureSpec.getSize(widthMeasureSpec),
				AppConstance.SCREEN_HEIGHT
						+ DisplayUtil.dipToPixels(getContext(), 50));
	}

	public void change() {
		if (currentState == 0) {
			currentState = 1;
			toTopAnimation();
		} else {
			currentState = 0;
			toBottomAnimation();
		}
	}

	public int getState() {
		return currentState;
	}

	private void toTopAnimation() {
		ObjectAnimator anim = ObjectAnimator.ofFloat(this, "y", 0,
				-DisplayUtil.dipToPixels(getContext(), 50));
		anim.setDuration(duration);
		anim.start();
	}

	private void toBottomAnimation() {
		ObjectAnimator anim = ObjectAnimator.ofFloat(this, "y",
				-DisplayUtil.dipToPixels(getContext(), 50), 0);
		anim.setDuration(duration);
		anim.start();
	}

}
